from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time

# 配置Selenium
driver = webdriver.Chrome()

# 打开登录页面
driver.get("https://www.zhihu.com/signin")

# 模拟输入账号密码
driver.find_element(By.NAME, "username").send_keys("zerowzj@163.com")
#driver.find_element(By.NAME, "password").send_keys("wzj0211432")
driver.find_element(By.XPATH, "//button[@type='submit']").click()

# 等待登录成功
time.sleep(5)

# 抓取用户首页的动态数据
# driver.get("https://www.zhihu.com/follow")
# time.sleep(3)

# 解析数据
# posts = driver.find_elements(By.CLASS_NAME, "List-item")
# for post in posts:
#     print(post.text)

# 关闭浏览器
driver.quit()